//
//  ByApiMine.m
//  chequanbao_ios
//
//  Created by mc on 2017/6/26.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByApiMine.h"

// model
#import "ByModelMinePoints.h"
#import "ByModelMineConsume.h"
#import "ByModelFriendAndRelative.h"

@implementation ByApiMine
// 获取车险金
+ (void)getMinePoints:(ByNetParamsModel *)model
              success:(void(^)(ByNetBaseResult *result))success
              failure:(void(^)(ByNetBaseResult *result))failure{
    static NSString *apiType = @"By_AccountScore_getInfo";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    // 必须参数
    [params setObject:model.uid forKey:@"account_id"];
    [params setObject:model.code_type forKey:@"account_type"];
    // 返回的responseObject 可能是字符串也可能是字典
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeDictionary
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           CodeLog(@"******** 获取账户车险金 -> 成功: %@", responseObject);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = responseObject;
           result.data = responseObject;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           CodeLog(@"******** 获取账户车险金 -> 失败: %@", error);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];

}

// 申请提现
+ (void)applyforcash:(ByNetParamsModel *)model
             success:(void(^)(ByNetBaseResult *result))success
             failure:(void(^)(ByNetBaseResult *result))failure{
    static NSString *apiType = @"By_WithdrawDeposit_apply";
    static NSInteger apiVersion = 102;
    int rand = arc4random() % 1000;
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    // 必须参数
    [params setObject:model.role_type forKey:@"account_type"];
    [params setObject:model.account_id forKey:@"account_id"];
    [params setObject:model.score forKey:@"score"];
    [params setObject:model.bank_card_name forKey:@"bank_card_name"];
    [params setObject:model.bank_card_no forKey:@"bank_card_no"];
    [params setObject:model.name forKey:@"name"];
    [params setObject:model.mobile forKey:@"mobile"];
    // 返回的responseObject 可能是字符串也可能是字典
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeString
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           CodeLog(@"******** 普通用户提现申请 -> 成功: %@", responseObject);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = responseObject;
           result.data = responseObject;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           CodeLog(@"******** 普通用户提现申请 -> 失败: %@", error);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];

}

// 获取账户变动记录（我的收入、我的支出）
+ (void)changeRecord:(ByNetParamsModel *)model
             success:(void(^)(ByNetBaseResult *result))success
             failure:(void(^)(ByNetBaseResult *result))failure{
    static NSString *apiType = @"By_AccountScore_getAccounts";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    // 必须参数
    [params setObject:model.uid forKey:@"uid"];
    [params setObject:model.role_type forKey:@"role_type"];
    [params setObject:model.change_type forKey:@"change_type"];
    [params setObject:model.page_index forKey:@"page_index"];
    [params setObject:model.page_size forKey:@"page_size"];
    // 返回的responseObject 可能是字符串也可能是字典
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeDictionary
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           CodeLog(@"******** 查询积分变动记录 -> 成功: %@", responseObject);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"查询积分成功";
           NSMutableDictionary *resDic = [[NSMutableDictionary alloc] init];
           NSMutableArray *tmp = [[NSMutableArray alloc] init];
           for (NSDictionary *dic in ((NSDictionary *)responseObject)[@"list"]) {
               ByModelMinePoints *model = [[ByModelMinePoints alloc] initContentWithDic:dic];
               [tmp addObject:model];
           }
           [resDic setObject:tmp forKey:@"list"];
           [resDic setObject:((NSDictionary *)responseObject)[@"count"] forKey:@"count"];
           result.data = resDic;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           CodeLog(@"******** 查询积分变动记录 -> 失败: %@", error);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];

}

+ (void)buyRecord:(ByNetParamsModel *)model
          success:(void(^)(ByNetBaseResult *result))success
          failure:(void(^)(ByNetBaseResult *result))failure{
    static NSString *apiType = @"By_Seller_queryConsume";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    // 必须参数
    [params setObject:model.uid forKey:@"uid"];
    [params setObject:model.page_index forKey:@"page_index"];
    [params setObject:model.page_size forKey:@"page_size"];
    // 返回的responseObject 可能是字符串也可能是字典
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeDictionary
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           CodeLog(@"******** 用户查询购买记录 -> 成功: %@", responseObject);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"查询积分成功";
           NSMutableDictionary *resDic = [[NSMutableDictionary alloc] init];
           NSMutableArray *tmp = [[NSMutableArray alloc] init];
           for (NSDictionary *dic in ((NSDictionary *)responseObject)[@"list"]) {
               ByModelMineConsume *model = [[ByModelMineConsume alloc] initContentWithDic:dic];
               [tmp addObject:model];
           }
           [resDic setObject:tmp forKey:@"list"];
           [resDic setObject:((NSDictionary *)responseObject)[@"count"] forKey:@"count"];
           result.data = resDic;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           CodeLog(@"********用户查询购买记录 -> 失败: %@", error);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
    

}

// 获取亲朋好友数据
+ (void)fetchCountInfo:(ByNetParamsModel *)model
               success:(void(^)(ByNetBaseResult *result))success
               failure:(void(^)(ByNetBaseResult *result))failure{
    static NSString *apiType = @"By_Seller_countInfo";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    // 必须参数
    [params setObject:model.account_id forKey:@"account_id"];
    [params setObject:model.account_type forKey:@"account_type"];
    // 返回的responseObject 可能是字符串也可能是字典
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeDictionary
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           CodeLog(@"******** 获取自身统计信息 -> 成功: %@", responseObject);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = responseObject;
           result.data = responseObject;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           CodeLog(@"******** 获取自身统计信息 -> 失败: %@", error);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
}

// 获取亲朋好友列表
+ (void)fetchFriendList:(ByNetParamsModel *)model
                success:(void(^)(ByNetBaseResult *result))success
                failure:(void(^)(ByNetBaseResult *result))failure{
    static NSString *apiType = @"By_Seller_getrelationship";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    // 必须参数
    [params setObject:model.uid forKey:@"uid"];
    [params setObject:model.type forKey:@"types"];
    [params setObject:model.page_no forKey:@"p"];
    // 返回的responseObject 可能是字符串也可能是字典
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeDictionary
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           CodeLog(@"******** 查询下级 -> 成功: %@", responseObject);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = responseObject;
           NSMutableDictionary *resDic = [[NSMutableDictionary alloc] init];
           NSMutableArray *tmp = [[NSMutableArray alloc] init];
           for (NSDictionary *dic in ((NSDictionary *)responseObject)[@"list"]) {
               ByModelFriendAndRelative *model = [[ByModelFriendAndRelative alloc] initContentWithDic:dic];
               [tmp addObject:model];
           }
           [resDic setObject:tmp forKey:@"list"];
           [resDic setObject:((NSDictionary *)responseObject)[@"count"] forKey:@"count"];
           result.data = resDic;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           CodeLog(@"******** 查询下级 -> 失败: %@", error);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
}
@end
